package com.jingbian.cppccbackend.controller.user;


import com.github.pagehelper.PageInfo;
import com.jingbian.cppccbackend.entity.Result;
import com.jingbian.cppccbackend.service.user.IActivitiesApplyService;
import com.jingbian.cppccbackend.utils.ResultUtil;
import com.jingbian.cppccbackend.vo.ActivityApplyVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author pum
 * @since 2025-02-28
 */
@RestController
@RequestMapping("/users/activityApply")
public class ActivitiesApplyController {

  @Autowired
  private IActivitiesApplyService activitiesApplyService;

  /**
   * 查询某个活动申请的人数
   */
  @GetMapping("/getList")
  public Result<PageInfo<ActivityApplyVO>> getActivitiesApplyList(@RequestParam int aid, @RequestParam int pageNum) {
    return ResultUtil.success(activitiesApplyService.getApplyList(aid, pageNum));
  }

  /**
   * 用户参与活动的报名
   * @param aid
   * @return Result<String>
   */
  @PostMapping("/joinActivity/{aid}")
  public Result<String> joinActivity(@PathVariable Integer aid) {
    boolean isJoin = activitiesApplyService.joinActivity(aid);
    if (isJoin) {
      return ResultUtil.success("参与成功！");
    }
    return ResultUtil.fail("您已报名该活动，请勿重复操作");
  }

  /**
   * 用户取消活动的报名
   * @param aid
   * @return Result<String>
   */
  @DeleteMapping("/deleteJoinActivity/{aid}")
  public Result<String> deleteJoinActivity(@PathVariable Integer aid) {
    activitiesApplyService.deleteJoinActivity(aid);
    return ResultUtil.success("取消参与成功");
  }
}
